package no.awi.wpd.probability;

import org.junit.Test;

import static no.awi.wpd.probability.ProbabilityDistribution.createBinomialProbabilityDistribution;
import static no.awi.wpd.probability.ProbabilityFunctions.rerollOnFailure;

public class ProbabilityDistributionIntTest {

    @Test
    public void testDiceStudy() {
        long startTime = System.currentTimeMillis();
        ProbabilityDistribution bd = createBinomialProbabilityDistribution(0.29, 1000);
        System.out.println("Ran ProbabilityDistribution.createBinomialProbabilityDistribution(0.29, 1000) in [" + (System.currentTimeMillis() - startTime) + "] ms.");
        System.out.println("P(169 or less):\t" + bd.getSumUnderTreshhold(169));
        System.out.println("P(169):\t" + bd.getProbabilityByValue(169));
    }
    
    @Test
    public void insaneCourageExample() {
        ProbabilityDistribution bd = createBinomialProbabilityDistribution(1.0 / 6, 2);
        System.out.println("*** Insane courage ***");
        double p = bd.getProbabilityByIndex(2);
        System.out.println("Normal:\t\t\t" + p);
        bd = createBinomialProbabilityDistribution(1.0 / 6, 2);
        p = rerollOnFailure(bd.getSumOverTreshhold(2));
        System.out.println("Reroll:\t\t\t" + p);
        bd = createBinomialProbabilityDistribution(1.0 / 6, 3);
        p = bd.getSumOverTreshhold(2);
        System.out.println("Cold blooded:\t\t" + p);
        bd = createBinomialProbabilityDistribution(1.0 / 6, 3);
        p = rerollOnFailure(bd.getSumOverTreshhold(2));
        System.out.println("Cold blooded, reroll:\t" + p);
    }
}
